#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int N=1e5+10;
int dist [N];
int n=1e5+10;
void bfs(int x,int y)
{
	memset(dist,-1,sizeof dist);
	queue<int> q;
	q.push(x);
	dist[x]=0;
	while(q.size())
   {
   	x=q.front();q.pop();
	int a=x+1,b=x-1,c=x*2;
	if(a<=n&&dist[a]==-1)
	{q.push(a);
   dist[a]=dist[x]+1;}
	if(b>0&&dist[b]==-1)
	{
	q.push(b);
	dist[b]=dist[x]+1;
	}
	if(c<=n&&dist[c]==-1)
	{q.push(c);
   dist[c]=dist[x]+1;}
	
	if(a==y||b==y||c==y)
	return;
   }
}
int main()
{
	int t,x,y;
	cin>>t;
	while(t--)
	{
		cin>>x>>y;
		bfs(x,y);
		cout<<dist[y]<<endl;
	}
	
	return 0;
}
